<?php

namespace app\admin\controller;

use think\facade\Request;
use app\common\Common;
use app\admin\service\UserService;

class User extends Base
{
    private $service;

    public function __construct(UserService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染用户列表页面
    public function index()
    {
        return view();
    }

    // 渲染用户详情页面
    public function info()
    {
        return view();
    }

    // 用户列表
    public function list()
    {
        $params = Request::param();

        $data = $this->service->getUserList($params);

        return Common::success($data);
    }

    /**
     * 用户详情
     * 
     * @author zhixiang0215@126.com
     * @param int id
     * @return json
     */
    public function detail()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\User::class)->scene('detail')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getUserDetail($params['id']);

        return Common::success($data);
    }

    // 获取用户的消费记录
    public function consumeRecord()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\User::class)->scene('consume_record')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getUserConsumeRecord($params);

        return Common::success($data);
    }

    // 获取用户的充值记录
    public function rechargeRecord()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\User::class)->scene('recharge_record')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getUserRechargeRecord($params);

        return Common::success($data);
    }

    // 获取用户的观看记录
    public function watchRecord()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\User::class)->scene('watch_record')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->getUserWatchRecord($params);

        return Common::success($data);
    }

    // 渲染赠币页面
    public function give()
    {
        return view();
    }

    // 赠用户k币
    public function givekCoins()
    {
        $params = Request::param();
        $data = $this->service->giveUserkCoins($params);

        if (isset($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success();
    }

    // 渲染用户分析数据页面
    public function analysis()
    {
        return view();
    }

    // 用户分析数据
    public function userAnalysis()
    {
        $params = Request::param();
        $data = $this->service->getUserAnalysisData($params);

        return Common::success($data);
    }

    public function black(){
        return view();
    }
}
